home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 045a / btp15.zip / STATS.PAS < prev    next >
Pascal/Delphi Source File  |  1991-11-09  |  7KB  |  221 lines

  1. PROGRAM Stats;                { (C) 1991 John C. Leon   last updated 11/9/91 }
  2.  
  3. {
  4. This program will report stats on ANY Btrieve file.  Just supply the name of
  5. any valid Btrieve file on the command line or when prompted.  We are not
  6. concerned with the record layout of a file at all in this program.  We just
  7. want stats, to illustrate use of the BFile object.
  8. }
  9.  
  10. {$IFDEF production} {$D-,R-,L-,S-} {$ENDIF}
  11.  
  12. USES
  13.    BTP;  {Crt unit not used at all, to permit redirection of program output
  14.           to file or printer.}
  15.  
  16. TYPE
  17.    PStatFile   = ^TStatFile;
  18.    TStatFile   = object(BFile)
  19.                     KeyType: string;
  20.                     procedure SetKeyType(KFlags: integer; EType: byte);
  21.                     end;
  22.  
  23. VAR
  24.    StatFile       : PStatFile;
  25.    StatFileName,
  26.    KeyType, TempS,
  27.    S1, S2         : string;
  28.    Counter,
  29.    KeyCount       : integer;
  30.    PriorSegmented,
  31.    HasDescKey     : boolean;
  32.  
  33. procedure TStatFile.SetKeyType(KFlags: integer; EType: byte);
  34. begin
  35. if (KFlags and Binary) = Binary then
  36.    KeyType := 'Unsigned'
  37.    else
  38.    begin
  39.    case EType of
  40.        0: KeyType := 'String  ';
  41.        1: KeyType := 'Integer ';
  42.        2: KeyType := 'Float   ';
  43.        3: KeyType := 'Date    ';
  44.        4: KeyType := 'Time    ';
  45.        5: KeyType := 'Decimal ';
  46.        6: KeyType := 'Money   ';
  47.        7: KeyType := 'Logical ';
  48.        8: KeyType := 'Numeric ';
  49.        9: KeyType := 'Bfloat  ';
  50.       10: KeyType := 'Lstring ';
  51.       11: KeyType := 'Zstring ';
  52.       14: KeyType := 'Unsigned';
  53.       15: KeyType := 'AutoInc ';
  54.       end;
  55.    end;
  56. end;
  57.  
  58. procedure DoFileStatLine;
  59. begin
  60.    if length(S1) < 37 then
  61.       for Counter := length(S1) to 37 do
  62.          S1 := S1 + ' ';
  63.    writeln(S1, S2);
  64. end;
  65.  
  66.  
  67. BEGIN
  68.    {get filename to act on and store it in uppercase}
  69.    if paramcount < 1 then
  70.       begin
  71.       write('Enter name of a Btrieve file: ');
  72.       readln(StatFileName);
  73.       end
  74.       else
  75.       StatFileName := paramstr(1);
  76.    for Counter := 1 to length(StatFileName) do
  77.       StatFileName[Counter] := upcase(StatFileName[Counter]);
  78.  
  79.    {open the file in read only mode}
  80.    StatFile := new(PStatFile, Init(StatFileName, ReadOnly));
  81.  
  82.    if BStatus <> 0 then
  83.  
  84.       writeln('Error opening Btrieve file.  Program terminated.')
  85.  
  86.       else
  87.  
  88.       begin
  89.  
  90.       HasDescKey := false;
  91.  
  92.       writeln;
  93.       writeln('BTP Stats - Version 1.5 - (C) 1991 John C. Leon.  All Rights Reserved.');
  94.       writeln;
  95.       writeln('File stats for ', StatFileName);
  96.       writeln;
  97.  
  98.       with StatFile^ do
  99.          begin
  100.          str(Specs.RecLen, TempS);
  101.          S1 :=('Record length    = ' + TempS);
  102.          S2 := 'Variable Length  = ';
  103.          if (Specs.FileFlags and VarLength) = VarLength then
  104.             begin
  105.             S2 := S2 + 'Yes  Free Space = ';
  106.             if (Specs.FileFlags and Free30) = Free30 then
  107.                S2 := S2 + '30%' else
  108.                if (Specs.FileFlags and Free20) = Free20 then
  109.                   S2 := S2 + '20%' else
  110.                   if (Specs.FileFlags and Free10) = Free10 then
  111.                      S2 := S2 + '10%' else
  112.                      S2 := S2 + '0%';
  113.             end
  114.             else
  115.             S2 := S2 + 'No';
  116.          DoFileStatLine;
  117.          str(Specs.NumKeys, TempS);
  118.          S1 := 'Number keys/segs = ' + TempS + ' / ';
  119.          str(NumSegs, TempS);
  120.          S1 := S1 + TempS;
  121.          S2 := 'Blank Truncation = ';
  122.          if (Specs.FileFlags and BlankTrunc) = BlankTrunc then
  123.             S2 := S2 + 'Yes' else S2 := S2 + 'No';
  124.          DoFileStatLine;
  125.          str(Specs.UnusedPgs, TempS);
  126.          S1 := 'Unused pages     = ' + TempS;
  127.          S2 := 'Preallocation    = ';
  128.          if (Specs.FileFlags and PreAllocate) = PreAllocate then
  129.             begin
  130.             str(Specs.PreAlloc, TempS);
  131.             S2 := S2 + 'Yes  Pages = ' + TempS;
  132.             end
  133.             else
  134.             S2 := S2 + 'No ';
  135.          DoFileStatLine;
  136.          str(Specs.PageSize, TempS);
  137.          S1 := 'Page size        = ' + TempS;
  138.          S2 := 'Data Compression = ';
  139.          if (Specs.FileFlags and DataComp) = DataComp then
  140.             S2 := S2 + 'Yes' else S2 := S2 + 'No';
  141.          DoFileStatLine;
  142.          str(NumRecs, TempS);
  143.          S1 := 'Number records   = ' + TempS;
  144.          S2 := 'Key Only File    = ';
  145.          if (Specs.FileFlags and KeyOnly) = KeyOnly then
  146.             S2 := S2 + 'Yes' else S2 := S2 + 'No';
  147.          DoFileStatLine;
  148.          writeln;
  149.          write('Key  Position  Length  Duplicates  Modifiable   Type    ');
  150.          writeln('Null    Total');
  151.          writeln;
  152.  
  153.          KeyCount       := 0;
  154.          PriorSegmented := false;
  155.  
  156.          for Counter := 1 to NumSegs do
  157.             with Specs.KeyArray[Counter-1] do
  158.                begin
  159.                write(KeyCount:3, KeyPos:8, KeyLen:8, '        ');
  160.                if (KeyFlags and Segmented) = Segmented then
  161.                   PriorSegmented := true;
  162.                if (KeyFlags and Segmented) <> Segmented then
  163.                   PriorSegmented := false;
  164.                if ((KeyFlags and Segmented) <> Segmented) and
  165.                   (PriorSegmented = false) then inc(KeyCount);
  166.                if (KeyFlags and Duplicates) = Duplicates then
  167.                   write('Yes') else write(' No');
  168.                if (KeyFlags and Modifiable) = Modifiable then
  169.                   write('         Yes   ') else write('         No    ');
  170.                SetKeyType(KeyFlags, ExtKeyType);
  171.                if (KeyFlags and AltCol) = AltCol then
  172.                   write(' *', KeyType) else write('  ', KeyType);
  173.                if (KeyFlags and Descending) = Descending then
  174.                   begin
  175.                   write(' <');
  176.                   HasDescKey := true;
  177.                   end
  178.                   else
  179.                   write('  ');
  180.                if (KeyFlags and Null) = Null then
  181.                   write(NullValue) else write('-- ');
  182.                write(NumUnique: 10);
  183.                writeln;
  184.                if (Counter + 13) = 23 then
  185.                   begin
  186.                   writeln;
  187.                   writeln('-- press Enter to continue');
  188.                   readln; writeln;
  189.                   end;
  190.  
  191.                end;                        {with Specs.KeyArray[Counter-1] do}
  192.  
  193.          if HasAltCol then
  194.             begin
  195.             writeln;
  196.             write('* Alternate Collating Sequence is: ');
  197.             for Counter := 1 to 8 do
  198.                write(AltColName[Counter]);
  199.             end;
  200.  
  201.          if HasDescKey then
  202.             begin
  203.             writeln;
  204.             write('< Indicates descending key segment');
  205.             end;
  206.  
  207.          writeln;
  208.  
  209.          BStatus := Close;
  210.  
  211.          end;                                              {with StatFile^ do}
  212.  
  213.       if BStatus <> 0 then
  214.          writeln('File could not be closed.  Status = ', BStatus);
  215.  
  216.       end; {if BStatus <> 0}
  217.  
  218.       dispose(StatFile, Done);
  219.  
  220. END.
  221.